﻿Imports System.Windows.Forms

Public Class MDIParent1

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
        ' Create a new instance of the child form.
        Dim ChildForm As New System.Windows.Forms.Form
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        ChildForm.Text = "Window " & m_ChildFormNumber

        ChildForm.Show()



        Dim frm As New frmMain
        frmMain.Show()

    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = OpenFileDialog.FileName
            ' TODO: Add code here to open the file.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" 

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolBarToolStripMenuItem.Click
        Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub subLoadtviewNAV()
        Dim cn As New SQLite.SQLiteConnection
        Dim da As New SQLite.SQLiteDataAdapter
        Dim ds As New DataSet
        Dim sSQL As String

        Dim nodBA As TreeNode, nodOpen As New TreeNode, nodClosed As New TreeNode

        nodBA = tviewNAV.Nodes("nodHomeRoot").Nodes("nodHChBankAccounts")
        nodOpen.Name = "nodHChBAOpen"
        nodOpen.Text = "Open"

        nodClosed.Name = "nodHChBAClosed"
        nodClosed.Text = "Closed"



        cn.ConnectionString = fGetConnectionString()
        cn.Open()

        sSQL = "SELECT ACCOUNTID, ACCOUNTNAME, STATUS FROM ACCOUNTLIST_V1 ORDER BY ACCOUNTNAME"

        da = New SQLite.SQLiteDataAdapter(sSQL, cn)
        da.Fill(ds, "ACCOUNTLIST_V1")


        For i = 0 To ds.Tables(0).Rows.Count - 1

            Select Case ds.Tables(0)(i).Item("STATUS").ToString.ToLower
                Case "open".ToLower
                    With nodOpen.Nodes
                        Dim nodTemp As New TreeNode
                        With nodTemp
                            .Name = "nodHChBAOpen_" & ds.Tables(0)(i).Item("ACCOUNTID")
                            .Text = ds.Tables(0)(i).Item("ACCOUNTNAME")
                            .Tag = ds.Tables(0)(i).Item("ACCOUNTID")
                        End With
                        .Add(nodTemp)

                        '.Add("nodHChBAOpen_" & ds.Tables(0)(i).Item("ACCOUNTID"), ds.Tables(0)(i).Item("ACCOUNTNAME"))
                    End With
                Case "Closed".ToLower
                    With nodClosed.Nodes
                        '.Add("nodHChBAOpen_" & ds.Tables(0)(i).Item("ACCOUNTID"), ds.Tables(0)(i).Item("ACCOUNTNAME"))
                        Dim nodTemp As New TreeNode
                        With nodTemp
                            .Name = "nodHChBA_" & ds.Tables(0)(i).Item("ACCOUNTID")
                            .Text = ds.Tables(0)(i).Item("ACCOUNTNAME")
                            .Tag = ds.Tables(0)(i).Item("ACCOUNTID")
                        End With
                        .Add(nodTemp)
                    End With
            End Select

        Next i


        '*// Add nodes when required
        If nodOpen.Nodes.Count > 0 Then nodBA.Nodes.Add(nodOpen)
        If nodClosed.Nodes.Count > 0 Then nodBA.Nodes.Add(nodClosed)



    End Sub


    Private Sub MDIParent1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        subLoadtviewNAV()

        cTransactionList.ConnectionString = fGetConnectionString()
        cTransactionList.Visible = True

    End Sub

    'Private Sub LoadAccount(accountID As Integer)

    '    With gridBackground
    '        .Visible = True

    '        .connection = fGetConnectionString()
    '        .addColumneToHide("TRANSID")

    '        '*// http://www.sqlite.org/lang_expr.html
    '        .SQLstring = "SELECT C1.TRANSID, C1.TRANSACTIONNUMBER, C1.TRANSDATE," _
    '                            & " CASE WHEN C1.TRANSCODE = 'Transfer' THEN 'Transfer from/to ' || A1.ACCOUNTNAME ELSE P1.PAYEENAME END AS PAYEE_ACCOUNT , (CAT1.CATEGNAME || ':' || SUB1.SUBCATEGNAME) AS CATEGORIES," _
    '                            & " C1.STATUS," _
    '                            & " CASE WHEN C1.TRANSCODE = 'Withdrawal' THEN C1.TRANSAMOUNT ELSE 0 END AS WITHDRAWAL," _
    '                            & " CASE WHEN C1.TRANSCODE = 'Deposit' THEN C1.TRANSAMOUNT ELSE 0 END AS DEPOSIT," _
    '                            & " 0 AS TOTAL, C1.NOTES" _
    '                        & " FROM CHECKINGACCOUNT_V1 C1" _
    '                            & " LEFT JOIN PAYEE_V1 P1" _
    '                                & " ON C1.PAYEEID = P1.PAYEEID" _
    '                            & " LEFT JOIN CATEGORY_V1 CAT1" _
    '                                & " ON C1.CATEGID = CAT1.CATEGID" _
    '                            & " LEFT JOIN SUBCATEGORY_V1 SUB1" _
    '                                & " ON C1.SUBCATEGID = SUB1.SUBCATEGID" _
    '                            & " LEFT JOIN ACCOUNTLIST_V1 A1" _
    '                                & " ON C1.TOACCOUNTID = A1.ACCOUNTID" _
    '                        & " WHERE C1.ACCOUNTID = " & accountID _
    '                        & " ORDER BY C1.TRANSDATE"

    '        .AutoResizeColumn(3)
    '        .AutoResizeColumn(4)

    '    End With
    'End Sub

    Private Sub tviewNAV_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles tviewNAV.AfterSelect

        If Not e.Node.Parent Is Nothing Then
            If e.Node.Parent.Name = "nodHChBAOpen" Then
                'LoadAccount(e.Node.Tag)
                cTransactionList.AccountID = e.Node.Tag


            End If
        End If
    End Sub

    Private Sub cTransactionList_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs)

    End Sub
End Class
